<template>
  <div class="app-container">
    <HighAgeDaysEdit  ref="openHighAgeDaysEdit" @refresh="refresh"></HighAgeDaysEdit>
    <el-form @submit.native.prevent :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px" :label-position="labelPosition">
        <el-form-item label="条码" prop="sptm">
        <el-input
          v-model="queryParams.sptm"
          placeholder="请输入条码"
          clearable
           @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="客户" prop="khmc">
        <el-select
            v-model="queryParams.khmc"
            placeholder="请输入客户"
            clearable
            @change="changeWarehouse"
            filterable
            :loading="selectClient5Loading || loading"
        >
            <el-option
                v-for="(item, index) in selectClient5List"
                :key="index"
                :label="item.khmc"
                :value="item.khmc"
            />
        </el-select>
      </el-form-item>
      <el-form-item label="入仓日期" prop="ssrqid">
        <el-date-picker
          v-model="queryParams.ssrqid"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="请输入入仓日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="仓库" prop="spckmc">
        <el-select
            v-model="queryParams.spckmc"
            placeholder="请选择"
            clearable
            @change="changeWarehouse"
            filterable
            :loading="selectWarehouse15Loading || loading"
        >
            <el-option
                v-for="item in selectWarehouse15List"
                :key="item.spckid"
                :label="item.spckmc"
                :value="item.spckid"
            />
        </el-select>
      </el-form-item>
      <el-form-item label="仓位" prop="ckcw1">
        <el-select
            v-model="queryParams.ckcw1"
            placeholder="请选择"
            clearable
            @change="changeWarehousePosition"
            filterable
            :loading="selectPosition2Loading || loading"
        >
            <el-option
                v-for="item in warehousePositionList"
                :key="item.liid"
                :label="item.ckcw"
                :value="item.liid"
            />
        </el-select>
      </el-form-item>
      <el-form-item label="柜号" prop="spgh">
        <el-input
          v-model="queryParams.spgh"
          placeholder="请输入柜号"
          clearable
           @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="批号" prop="spbh">
        <el-input
          v-model="queryParams.spbh"
          placeholder="请输入批号"
          clearable
           @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="物品规格" prop="spzs">
        <el-input
          v-model="queryParams.spzs"
          placeholder="请输入物品规格"
          clearable
           @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="品牌" prop="spcd">
        <el-input
          v-model="queryParams.spcd"
          placeholder="请输入品牌"
          clearable
           @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="库存截止日" prop="dayi">
        <el-date-picker
          v-model="queryParams.dayi"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="请输入库存截止日">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="条码备注" prop="spbz">
        <el-input
          v-model="queryParams.spbz"
          placeholder="请输入条码备注"
          clearable
           @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="类型" prop="spdms">
        <el-select
            v-model="queryParams.spdms"
            placeholder="请选择类型"
            multiple
            clearable
        >
            <el-option
                v-for="item in type"
                :key="item.value"
                :label="item.label"
                :value="item.value"
            />
        </el-select>
      </el-form-item>
      <el-form-item label="外部单号" prop="wbdh">
        <el-input
          v-model="queryParams.wbdh"
          placeholder="请输入外部单号"
          clearable
           @keyup.enter.native="enterClick"
        />
      </el-form-item>
      
      <el-form-item>
        <el-checkbox v-model="queryParams.jqcz" label="精确查找" true-label="1" @change="getList"></el-checkbox>
        <el-checkbox v-model="queryParams.gaoling" label="只显示高龄货物" true-label="1" @change="getList"></el-checkbox>
        <el-checkbox v-model="queryParams.ally" label="查看所有记录" true-label="1" @change="getList"></el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
     <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain size="mini" @click="settingHighAgeDay"  v-hasPermi="['zhcloud:sjzl:detail']">设置高龄货物天数</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="primary" plain size="mini" @click="handleExport" v-hasPermi="['zhcloud:sjzl:export']">导出Excel</el-button>
        </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      :data="goodsOverviewList"
    >
      <af-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="left">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="historyDetail(scope.row)"
            v-hasPermi="['zhcloud:sjzl:list']"
          >查看历史</el-button>
        </template>
      </af-table-column>
      <af-table-column prop="spdm" label="类型" fixed="left"></af-table-column>
      <!-- <af-table-column prop="wbdh" label="外部单号"></af-table-column> -->
      <af-table-column prop="allName" label="客户"></af-table-column>
      <af-table-column prop="spzs" label="物品规格"></af-table-column>
      <af-table-column prop="spbh" label="批号"></af-table-column>
      <af-table-column prop="spgh" label="柜号"></af-table-column>
      <af-table-column prop="spcd" label="品牌"></af-table-column>
      <af-table-column prop="spjs" label="剩余件数"></af-table-column>
      <af-table-column prop="spsl" label="剩余重量(吨)"></af-table-column>
      <af-table-column prop="spckmc" label="仓库"></af-table-column>
      <af-table-column prop="ckcw" label="仓位"></af-table-column>
      <af-table-column prop="ssrqid" label="入仓日期"></af-table-column>
      <af-table-column prop="days" label="结存天数"></af-table-column>
      <af-table-column prop="change" label="货转次数"></af-table-column>
      <af-table-column prop="sptm" label="客户条码"></af-table-column>
      <af-table-column prop="sptmc" label="仓库条码"></af-table-column>
      <af-table-column prop="spbz" label="条码备注" width="150" :show-overflow-tooltip="true"></af-table-column>
      <af-table-column prop="spjsk" label="剩余质押查看件数"></af-table-column>
      <af-table-column prop="spslk" label="剩余质押查看吨数"></af-table-column>
    </el-table>
     <pagination
        v-show="total>0"
        :total="total"
        :page.sync="pageNum"
        :limit.sync="pageSize"
        @pagination="getList"
      />
  </div>

</template>

<script>
import { getGoodsOverviewList, selectClient5 } from "@/api/storage/dataOverview/goodsOverview";
import { selectPosition2 } from "@/api/storage/warehousePosition"
import { selectWarehouse15 } from "@/api/storage/warehouse"
import HighAgeDaysEdit from './highAgeDaysEdit.vue'

export default {
  name: "GoodsOverview",
  components:{ HighAgeDaysEdit },
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //对齐
      labelPosition: "right",
      //加载列表
      loading: true,
      //客户加载
      selectClient5Loading: true,
      //仓库加载
      selectWarehouse15Loading: true,
      //仓位加载
      selectPosition2Loading: false,
      //审核状态
      type:[{
        value: "普通",
        label:"普通"
      },{
        value: "担保",
        label:"担保"
      },{
        value: "冻结",
        label:"冻结"
      }],
      goodsOverviewDate:'',
      // 查询参数
      queryParams: {
        ally: "",
        ckcw1: "",
        day: "",
        dayi: "",
        gaoling: "",
        jqcz: "",
        khmc: "",
        spbh: "",
        spbz: "",
        spcd: "",
        spckmc: "",
        //spdm: "",
        spdms:[],
        spgh: "",
        spmc: "",
        sptm: "",
        spzs: "",
        ssrqid: "",
        wbdh: "",
        downloadType:"json"
      },
      //获取仓位参数
      selectPositionQuery:{
         spckid:""
      },
      //获取客户参数
      selectClientQuery: {
        name1:""
      },
      //仓位列表
      warehousePositionList:[],
      //批量审核数据
      selection:[],
      // 货物入仓列表
      goodsOverviewList: [],
      //仓库列表
      selectWarehouse15List:[],
      //客户列表
      selectClient5List: [],
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  beforeRouteEnter(to, from, next) {
    const params = to.params
    next(vm => {   
      if(Object.keys(params).length > 0) {
        if(to.params.refresh == true) {
          vm.getList()
        }
      }
    })
  },
  created() {
    this.getWarehouse()
    this.getSelectClient5()
    this.getList()
  },
  methods: {
     /**获取客户 */
    getSelectClient5() {
      this.selectClient5Loading = true
      selectClient5(this.selectClientQuery).then(response => {
        this.selectClient5List = response.data
        this.selectClient5Loading = false
      });
    },
    /**获取仓库 */
    getWarehouse() {
      this.selectWarehouse15Loading = true
      selectWarehouse15({}).then(response => {
        this.selectWarehouse15List = response.data
        this.selectWarehouse15Loading = false
      });
    },
    /**获取仓位 */
    getWarehousePosition() {
      this.selectPosition2Loading = true
      selectPosition2(this.selectPositionQuery).then(response => {
        this.warehousePositionList = response.data
        this.selectPosition2Loading = false
      });
    },
    /** 查询货物入仓列表 */
    getList() {
      this.loading = true
      getGoodsOverviewList(this.queryParams, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.goodsOverviewList = response.rows;
        this.total = response.total;
        this.loading = false
      });
    },

    /**选择仓库 */
    changeWarehouse(id) {
      this.selectPositionQuery.spckid = id
      this.queryParams.ckcw1 = ""
      this.warehousePositionList = []
      if(this.selectPositionQuery.spckid) {
        this.getWarehousePosition()
      }
      this.getList()
    },
    /**选择仓位 */
    changeWarehousePosition() {
      this.getList()
    },

    /**设置高龄货物天数 */
    settingHighAgeDay() {
      this.$refs.openHighAgeDaysEdit.open()
    },

    // /**类型改变 */
    // changeTypeState() {
    //   this.getList()
    // },

    /** 导出数据*/
    handleExport() {
      this.download('/storage/sjzl/export', this.queryParams, `货物总览_${new Date().getTime()}.xlsx`)
    },

    /**查看历史 */
    historyDetail(data) {
      this.$router.push({path:"/storage/dataOverview/goodsOverview/goodsOverviewHistoryDetail", query:data})
    },

    /**enter键触发 */
    enterClick(e) {
      this.getList()
    },
    /** 刷新数据*/
    refresh() {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset()
      this.getWarehouse()
      this.getSelectClient5()
      this.getList()
    },
    reset() {
      Object.assign(this.$data, this.$options.data())
    },
  }
};
</script>
